import { Component,OnInit,OnDestroy } from '@angular/core';

import { DashboradAddService } from './dashborad.add.service';

import {AppSettings} from '../../../app.settings';

import { Subscription } from 'rxjs';

@Component({
  selector: 'dashborad-add',
  templateUrl: './dashborad.add.html',
  providers: [DashboradAddService]
})

export class DashboradAddComponent {

  constructor(private service: DashboradAddService,private appSettings:AppSettings) { }
  // pages data
  vm: any = {
    page: 1,
    table: {
      table: [],
      count: 0
    }
  };
  // 参数
  param: any = {
    page: 0,
    start: 0,
    rows: 10,
    catName: '',
    categoryLevel: 2,
    brandName: '""'
  };


  ngOnInit(){

    this.getHttp(this.param);

  }

  ngOnDestroy() {

    if (this.busy) {
      this.busy.unsubscribe();
    }

  }



  // search
  search() {
    if (this.param.catName == '') {
      return;
    }
    this.getHttp(this.param);
  }

  //分页
  pageChanged(currentPage) {

    // console.log(currentPage);

    this.vm.page = currentPage;

    this.param.start = (currentPage - 1) * this.param.rows;

    this.getHttp(this.param);

  }

  busy: Subscription;
  getHttp(param) {

    this.busy = this.service.getSearchCat(param).subscribe((res: any) => {
      this.vm.table.table = res.data.value;

      this.vm.table.count = res.data.count;


    }, () => { });
  }


}
